<title>利润计算</title>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>会员入口</cite></a>
        <a><cite>会员管理</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="app-content-list">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn" lay-submit lay-filter="LAY-temu-usermall-pay">
                        <i class="layui-icon layui-icon-rmb layuiadmin-button-btn"></i>激活店铺
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <table id="LAY-temu-usermall-list" lay-filter="LAY-temu-usermall-list">
            </table>
        </div>
    </div>
</div>
<script>
    layui.use('usermall', layui.factory('usermall')).use(['admin', 'table'], function () {
        var $ = layui.$
            , admin = layui.admin
            , table = layui.table
            , form = layui.form
            , setter = layui.setter;

        var mallIdList = [];
        table.render({
            elem: '#LAY-temu-usermall-list'
            , url: '/temu/queryUserMallList'
            , headers: {'access_token': layui.data(setter.tableName)[setter.request.tokenName]}
            , method: 'post'
            , height: 'full-250'
            , cols: [[
                {checkbox: true, fixed: true, title: '😊'},
                {field: 'mallName', title: '店铺名称'},
                {
                    field: 'vipState', title: '会员状态', templet: function (d) {
                        if (d.vipState == '0') {
                            return '未激活'
                        } else {
                            return '已激活';
                        }
                    }
                },
                {field: 'expiringTime', title: '到期时间'},
            ]]
            , text: {none: '暂无数据'}
        });

        table.on('checkbox(LAY-temu-usermall-list)', function (obj) {
            mallIdList = [];
            var id = obj.config.id;
            var checkStatus = table.checkStatus(id);
            var data = checkStatus.data;
            if (data.length > 0) {
                $.each(data, function (index, item) {
                    mallIdList.push(item.mallId);
                });
            }
            console.log(mallIdList);
        });

        form.on('submit(LAY-temu-usermall-pay)', function (data) {
            if (mallIdList.length == 0) {
                layer.msg('请至少选择一家店铺');
                return;
            }
            layer.confirm('确定为已勾选的店铺充值？', function (index) {
                admin.req({
                    url: '/temu/updateVipState',
                    type: 'post',
                    data: {mallIdList:mallIdList},
                    done: function (data) {
                        layer.msg('店铺激活成功');
                        table.reload('LAY-temu-usermall-list');
                    }
                })
                layer.close(index);
            });
        })
    });
</script>
